//
//  HMDengLuViewController.m
//  HMPersonalDoctor
//
//  Created by yongzhen on 16/9/11.
//  Copyright © 2016年 geduo. All rights reserved.
//

#import "HMDengLuViewController.h"
#import <SMS_SDK/SMSSDK.h>
@interface HMDengLuViewController ()<UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *phoneNumber;
@property (weak, nonatomic) IBOutlet UITextField *yanzheng;

@end

@implementation HMDengLuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)getYanZheng:(id)sender {
    /*
    *  @from                    v1.1.1
    *  @brief                   获取验证码(Get verification code)
    *
    *  @param method            获取验证码的方法(The method of getting verificationCode)
    *  @param phoneNumber       电话号码(The phone number)
    *  @param zone              区域号，不要加"+"号(Area code)
    *  @param customIdentifier  自定义短信模板标识 该标识需从官网http://www.mob.com上申请，审核通过后获得。(Custom model of SMS.  The identifier can get it  from http://www.mob.com  when the application had approved)
    *  @param result            请求结果回调(Results of the request)
    */
    
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodVoice
                            phoneNumber:self.phoneNumber.text
                                   zone:@"86"
                       customIdentifier:nil
                                 result:^(NSError *error) {
                                     if (!error) {
                                         NSLog(@"获取成功");
                                         
                                     }else{
                                         NSLog(@"错误信息%@",error);
                                     }
                                 }];
    

    
    
}
- (IBAction)dengLu:(id)sender {
    
    [SMSSDK commitVerificationCode:self.phoneNumber.text
                       phoneNumber:self.yanzheng.text
                              zone:@"86"
                            result:^(NSError *error) {
                                if (!error) {
                                    NSLog(@"验证成功");
                                    [self saveToShaHe];
                                }else{
                                    NSLog(@"验证失败");
                                    UIAlertView *alert =  [[UIAlertView alloc]initWithTitle:@"验证码错误" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                                    [alert show];
                                }
                            }];
    

}
-(void)saveToShaHe
{
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    
    NSLog(@"%@",path);
    
    NSDictionary *info = @{@"phoneNumber":self.phoneNumber.text};
    [info writeToFile:[NSString stringWithFormat:@"%@/user.plist",path] atomically:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
